﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Door : MonoBehaviour
{
    Animator anim;
    BoxCollider2D coll;
    private PlayerConllter player;
    private Enemy enemy;

    void Start()
    {
        anim = GetComponent<Animator>();
        coll = GetComponent<BoxCollider2D>();
        player = FindObjectOfType<PlayerConllter>();
        enemy = FindObjectOfType<Enemy>();
        coll.enabled = false; //碰撞器不启动
    }

    void Update()
    {
        if(enemy && enemy.enemyList.Count < 1){
            OpenDoor();
        }
    }

    public void OpenDoor()
    {
        anim.Play("open");
        coll.enabled = true;
    }


    //Enter 进入检测
    public void OnTriggerStay2D(Collider2D collision)
    {
        Debug.Log(collision);
        if(collision.gameObject.CompareTag("Player")){
            Debug.Log("玩家进入");
            player.isDoorInside = true;
        }
    }

}
